﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class OrbitalCommand : MonoBehaviour {

	public GameObject baseObject;
	public Transform rallyPoint;
	public float spawnTime = 2.5f;
	public float spawnCounter = 1.0f;
	public int spawnSize = 0;
	public int spawnSizeMax = 100;

	public Text outputTextStatus;

	void FixedUpdate() {

		spawnCounter += Time.fixedDeltaTime / spawnTime;

		if (spawnCounter > 1) {
			spawnCounter --;
			if (spawnSize >= spawnSizeMax) return;
		
			GameObject n = Instantiate(baseObject, new Vector3(0,5,0), baseObject.transform.localRotation * Quaternion.Euler (0, Random.Range (0, 360), 0)) as GameObject;
			n.name = "clone";			
			n.transform.SetParent(rallyPoint);
			n.SetActive(true);

			spawnSize++;

			if (!outputTextStatus) return;
			outputTextStatus.text =  spawnSize + " Vehicles";
		}

	}

}
